package com.xmy.stream;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * 实现用户筛选
 * 1. 用户id必须是偶数
 * 2. 年龄必须大于23岁
 * 3. 用户名转为大写
 * 4. 按照用户名倒序排序
 * 5. 只输出一个用户
 */
public class Test {
    public static void main(String[] args) {
        User u1 = new User(1,"a",21);
        User u2 = new User(2,"b",22);
        User u3 = new User(3,"c",23);
        User u4 = new User(4,"d",24);
        User u5 = new User(6,"e",25);
        // 集合就是存储
        List<User> list = Arrays.asList(u1,u2,u3,u4,u5);

        //计算交给Stream流
        list.stream()
                .filter(u->u.getId()%2==0)
                .filter(u->u.getAge()>23)
                .map(user -> {user.setName(user.getName().toUpperCase());return user;})
                .sorted(Comparator.comparing(User::getName).reversed())
                .limit(1)
                .forEach(System.out::println);
    }
}
